﻿using Microsoft.EntityFrameworkCore;

namespace MachineVision.Domain
{
    public class VisionDbContext : DbContext
    {
        public VisionDbContext(DbContextOptions<VisionDbContext> options) : base(options) {
            
        }

        public DbSet<TemperatureInfo> TemperatureInfos { get; set; }
        public DbSet<Token_YunMou> Tokens_YunMou { get; set; }
        public DbSet<MissionWorkNum> MissionWorkNums { get; set; }
        public DbSet<MissionHistoryInfo> MissionHistoryInfos { get; set; }
        public DbSet<WarningInfo> WarningInfos { get; set; }
        public DbSet<PatrolCar> PatrolCars { get; set; }
        public DbSet<PatrolGroup> PatrolGroups { get; set; }
        public DbSet<Menu> Menus { get; set; }


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            //modelBuilder.Entity<PatrolCar>().HasOne(s=>s.Group).WithMany(a=>a.Cars).HasForeignKey(s=>s.GroupId);
            modelBuilder.Entity<PatrolGroup>().HasMany(s => s.Cars).WithOne(a => a.Group).HasForeignKey(a=>a.GroupId);
            modelBuilder.Entity<Menu>().HasMany(s => s.Pages);
            modelBuilder.AddSeed();
            //modelBuilder.Entity<TemperatureInfo>().HasData(
            //    new TemperatureInfo() { CreateTime = DateTime.Parse("2022-08-10 12:00:00"), Date = new DateOnly(2022,8,10), Time = new TimeOnly(0,0,0), TemperatureC=50, Description=""}
            //    , new TemperatureInfo() { CreateTime = DateTime.Parse("2022-08-10 12:00:00"), Date = new DateOnly(2022, 8, 10), Time = new TimeOnly(0, 0, 1), TemperatureC = 55, Description = "" }
            //    ,new TemperatureInfo() { CreateTime = DateTime.Parse("2022-08-10 12:00:00"), Date = new DateOnly(2022, 8, 10), Time = new TimeOnly(0, 0, 2), TemperatureC = 52, Description = "" });
        }

    }
    
}